import { createRouter, createWebHistory, type Router } from 'vue-router';
import Layout from '@/layout/index.vue';

export enum RouteNameEnum {
  // 登录页
  LOGIN = 'login',
  // 404
  PAGE_404 = 'page404',
  // 403
  PAGE_403 = 'page403',
  // 布局根路由
  LAYOUT_ROOT = 'layoutRoot',
  // 首页
  HOME = 'home',
  // 个人中心
  PROFILE = 'profile',
  // 分配角色
  AUTH_ROLE = 'AuthRole',
  // 分配用户
  AUTH_USER = 'AuthUser',
}

export const routes = [
  {
    name: RouteNameEnum.LOGIN,
    path: '/login',
    component: () => import('@/views/login/index.vue'),
  },
  {
    name: RouteNameEnum.PAGE_404,
    path: '/404',
    component: () => import('@/views/404/index.vue'),
  },
  {
    name: RouteNameEnum.PAGE_403,
    path: '/403',
    component: () => import('@/views/403/index.vue'),
  },
  {
    name: RouteNameEnum.LAYOUT_ROOT,
    path: '/',
    component: Layout,
    children: [
      {
        name: RouteNameEnum.HOME,
        path: '',
        component: () => import('@/views/home/index.vue'),
        meta: { title: '首页', icon: 'HomeFilled' },
      },
      {
        name: RouteNameEnum.PROFILE,
        path: 'profile',
        hidden: true,
        component: () => import('@/views/profile/index.vue'),
        meta: { title: '个人中心' },
      },
    ],
  },
];

export const route404 = {
  path: '/:pathMatch(.*)*',
  redirect: '/404',
};

export const dynamicRoutes = [
  {
    name: RouteNameEnum.AUTH_ROLE,
    path: 'system/user-auth/role/:userId',
    component: () => import('@/views/modules/system/user/authRole.vue'),
    permissions: ['system:user:edit'],
    meta: { title: '分配角色', activeMenu: '/system/user' },
  },
  {
    name: RouteNameEnum.AUTH_ROLE,
    path: 'system/role-auth/user/:roleId',
    component: () => import('@/views/modules/system/role/authUser.vue'),
    permissions: ['system:role:edit'],
    meta: { title: '分配角色', activeMenu: '/system/role' },
  },
];

const router: Router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

export default router;
